/*
 * UI.java
 *
 * Created on Nov 29, 2012, 10:31:41 PM
 */
package mpscheduling;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.SpinnerNumberModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author jesseday
 */
public class UI extends javax.swing.JFrame {
    
    public Scheduler s;
    public ArrayList<Integer> processorAlgorithms = new ArrayList<Integer>();
    public ArrayList<Integer> processorTimeQuantums = new ArrayList<Integer>();
    
    /** Creates new form UI */
    public UI() {
        initComponents();
        String fname = (new File(UI.class.getProtectionDomain().getCodeSource().getLocation().getPath()).toString());
        int i = fname.indexOf("MPScheduling.jar");
        if(i>0)
            filename.setText(fname.substring(0, i));
    }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        processes = new javax.swing.JSpinner();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        infoTable = new javax.swing.JTable();
        processors = new javax.swing.JSpinner();
        jSeparator2 = new javax.swing.JSeparator();
        avgTT = new javax.swing.JTextField();
        avgWT = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        algo = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        tquantum = new javax.swing.JSpinner();
        useFile = new javax.swing.JCheckBox();
        filename = new javax.swing.JTextField();
        processor = new javax.swing.JSpinner();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        useCommon = new javax.swing.JCheckBox();
        processors2 = new javax.swing.JSpinner();
        algo2 = new javax.swing.JComboBox();
        useDifferent = new javax.swing.JCheckBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        tquantum1 = new javax.swing.JSpinner();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        pull = new javax.swing.JCheckBox();
        push = new javax.swing.JCheckBox();
        jLabel17 = new javax.swing.JLabel();
        pushFactor = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        processes.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1));

        jButton1.setText("Simulate");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel3.setText("Number of Processes (1-100)");

        jLabel2.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel2.setText("Number of Processors (1-20)");

        jLabel1.setFont(new java.awt.Font("Geneva", 1, 18));
        jLabel1.setText("Multiprocessor Scheduling Simluator");

        infoTable.setFont(new java.awt.Font("Geneva", 0, 12));
        infoTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "P Num", "Arrival ", "Burst ", "Turnaround", "Wait "
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(infoTable);

        processors.setModel(new javax.swing.SpinnerNumberModel(1, 1, 20, 1));
        processors.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                processorsStateChanged(evt);
            }
        });

        avgTT.setText("0.0");

        avgWT.setText("0.0");
        avgWT.setSize(new java.awt.Dimension(84, 28));

        jLabel4.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel4.setText("Average TT:");

        jLabel5.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel5.setText("Average WT:");

        jLabel6.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel6.setText("Sorting Algorithm");

        algo.setFont(new java.awt.Font("Geneva", 0, 13));
        algo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SRTF", "RR", "FCFS" }));
        algo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algoActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel7.setText("Time Quantum (1-200)");

        tquantum.setModel(new javax.swing.SpinnerNumberModel(1, 1, 200, 1));
        tquantum.setEnabled(false);

        useFile.setFont(new java.awt.Font("Geneva", 0, 13));
        useFile.setText("Use Input File:");
        useFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useFileActionPerformed(evt);
            }
        });

        filename.setText("info.txt");
        filename.setEnabled(false);

        processor.setModel(new javax.swing.SpinnerNumberModel(1, 1, 20, 1));
        processor.setEnabled(false);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Start Time", "Stop Time", "Process Number"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jButton2.setText("Set Gantt Values");
        jButton2.setEnabled(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel9.setText("Processor Number");

        jLabel10.setFont(new java.awt.Font("Geneva", 0, 18));
        jLabel10.setText("Gantt Values");

        useCommon.setFont(new java.awt.Font("Geneva", 0, 13));
        useCommon.setSelected(true);
        useCommon.setText("Common Ready Queue");
        useCommon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useCommonActionPerformed(evt);
            }
        });

        processors2.setModel(new javax.swing.SpinnerNumberModel(1, 1, 1, 1));
        processors2.setEnabled(false);
        processors2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                processors2StateChanged(evt);
            }
        });

        algo2.setFont(new java.awt.Font("Geneva", 0, 13));
        algo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SRTF", "RR", "FCFS" }));
        algo2.setEnabled(false);
        algo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algo2ActionPerformed(evt);
            }
        });

        useDifferent.setFont(new java.awt.Font("Geneva", 0, 13));
        useDifferent.setText("Use Different Algorithms ");
        useDifferent.setEnabled(false);
        useDifferent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useDifferentActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel11.setText("Processor Number");

        jLabel12.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel12.setText("Algorithm");

        jLabel13.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel13.setText("Select Processor Algorithm");

        jLabel14.setFont(new java.awt.Font("Geneva", 0, 18));
        jLabel14.setText("Scheduling Statistics");

        tquantum1.setModel(new javax.swing.SpinnerNumberModel(1, 1, 200, 1));
        tquantum1.setEnabled(false);
        tquantum1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tquantum1StateChanged(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel15.setText("Time Quantum (1-200)");

        jLabel16.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel16.setText("Load Balancing");

        pull.setFont(new java.awt.Font("Geneva", 0, 13)); // NOI18N
        pull.setText("Pull (when processor is idle)");
        pull.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pullActionPerformed(evt);
            }
        });

        push.setFont(new java.awt.Font("Geneva", 0, 13)); // NOI18N
        push.setText("Push when processor has ");
        push.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pushActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Geneva", 0, 13));
        jLabel17.setText("processes in its ready queue");

        pushFactor.setModel(new javax.swing.SpinnerNumberModel(1, 1, 10, 1));
        pushFactor.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                pushFactorStateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1195, Short.MAX_VALUE)
                            .add(jSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1195, Short.MAX_VALUE)))
                    .add(layout.createSequentialGroup()
                        .add(297, 297, 297)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(39, 39, 39)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(110, 110, 110)
                                .add(jLabel14))
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 396, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(layout.createSequentialGroup()
                                .add(15, 15, 15)
                                .add(jLabel4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(avgTT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel5)
                                .add(1, 1, 1)
                                .add(avgWT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(116, 116, 116)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 313, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(layout.createSequentialGroup()
                                    .add(jLabel9)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                    .add(processor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jButton2)))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(jLabel10)
                                .add(120, 120, 120)))))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .add(90, 90, 90)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(layout.createSequentialGroup()
                            .add(jLabel3)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(processes))
                        .add(layout.createSequentialGroup()
                            .add(jLabel2)
                            .add(13, 13, 13)
                            .add(processors)))
                    .add(layout.createSequentialGroup()
                        .add(jLabel7)
                        .add(22, 22, 22)
                        .add(tquantum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(jLabel6)
                        .add(35, 35, 35)
                        .add(algo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 87, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(50, 50, 50)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(useFile)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(filename, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(29, 29, 29)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(useDifferent)
                                    .add(useCommon))))
                        .add(17, 17, 17))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jButton1)
                        .add(77, 77, 77)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(22, 22, 22)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel13)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 183, Short.MAX_VALUE)
                                .add(jLabel16)
                                .add(120, 120, 120))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(jLabel11)
                                        .add(36, 36, 36)
                                        .add(processors2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(layout.createSequentialGroup()
                                        .add(24, 24, 24)
                                        .add(jLabel12)
                                        .add(55, 55, 55)
                                        .add(algo2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(40, 40, 40)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(pull)
                                    .add(layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                            .add(jLabel17)
                                            .add(push))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(pushFactor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(32, Short.MAX_VALUE))))
                    .add(layout.createSequentialGroup()
                        .add(7, 7, 7)
                        .add(jLabel15)
                        .add(18, 18, 18)
                        .add(tquantum1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(0, 790, Short.MAX_VALUE)
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(0, 445, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel2)
                                    .add(processors, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jLabel3))
                                    .add(layout.createSequentialGroup()
                                        .add(8, 8, 8)
                                        .add(processes, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(useFile)
                                    .add(filename, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(useCommon)))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(useDifferent)
                                .add(18, 18, 18)
                                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 38, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(14, 14, 14)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(algo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel6))
                                .add(12, 12, 12)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel7)
                                    .add(tquantum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel13)
                            .add(jLabel16))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel11)
                            .add(processors2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(pull))
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(jLabel12)
                                    .add(algo2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(tquantum1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel15)))
                            .add(layout.createSequentialGroup()
                                .add(5, 5, 5)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(pushFactor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(layout.createSequentialGroup()
                                        .add(push)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jLabel17)))))))
                .add(33, 33, 33)
                .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(40, 40, 40)
                        .add(jLabel14)
                        .add(21, 21, 21)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 223, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel5)
                            .add(avgWT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(avgTT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel4)))
                    .add(layout.createSequentialGroup()
                        .add(26, 26, 26)
                        .add(jLabel10)
                        .add(22, 22, 22)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jButton2)
                            .add(processor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel9))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(0, 322, Short.MAX_VALUE)
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(0, 314, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        
        SpinnerNumberModel pmodel1 = (SpinnerNumberModel)processors.getModel();
        int p1 = pmodel1.getNumber().intValue();
        
        SpinnerNumberModel pmodel2 = (SpinnerNumberModel)processes.getModel();
        int p2 = pmodel2.getNumber().intValue();
        
        SpinnerNumberModel qmodel = (SpinnerNumberModel)tquantum.getModel();
        int quantum = qmodel.getNumber().intValue();
        
        SpinnerNumberModel pushmodel = (SpinnerNumberModel)pushFactor.getModel();
        int pFactor = pushmodel.getNumber().intValue();
        
        processor.setValue(1);
        
        int anum = algo.getSelectedIndex();
        
        boolean common = useCommon.isSelected();
        
        s = new Scheduler(p1,p2,quantum,filename.getText(),useFile.isSelected(),
                anum,common);
        
        if(!useCommon.isSelected())
        {
            if(push.isSelected())
                s.push = true;
            if(pull.isSelected())
                s.pull = true;
            s.pushFactor = pFactor;
            if(useDifferent.isSelected())
            {
                for(int i=0; i<p1; i++)
                {
                    s.createProcessor(i, processorAlgorithms.get(i), 
                            processorTimeQuantums.get(i));
                }
            }else
            {
                for(int i=0; i<p1; i++)
                {
                    s.createProcessor(i);
                }
            }
        }
        s.run();
        
        ArrayList<Process> processList = s.getProcessList();
        Process current;
        int pnum, arr, bur, wait, turn;
        double aTT = 0, aWT = 0;
        
        DefaultTableModel tmodel = (DefaultTableModel)infoTable.getModel();
        
        tmodel.setRowCount(0);
        tmodel.setRowCount(processList.size());
                
        for(int i=0; i<processList.size(); i++)
        {
            current = processList.get(i);
            pnum = current.processNum();
            arr = current.arrivalTime();
            bur = current.initialBurst();
            wait = current.waitTime();
            turn = current.turnaroundTime();
            aTT += processList.get(i).turnaroundTime();
            aWT += processList.get(i).waitTime();
            
            tmodel.setValueAt(pnum, i, 0);
            tmodel.setValueAt(arr, i, 1);
            tmodel.setValueAt(bur, i, 2);
            tmodel.setValueAt(turn, i, 3);
            tmodel.setValueAt(wait, i, 4);
        }
        
        aTT /= processList.size();
        aWT /= processList.size();
        
        String t = new Double(aTT).toString();
        String w = new Double(aWT).toString();
        
        t = (t.length()<7) ? t : t.substring(0, 6);
        w = (w.length()<7) ? w : w.substring(0, 6);
        
        avgTT.setText(t);
        avgWT.setText(w);
        
        TableRowSorter<TableModel> sort = new TableRowSorter<TableModel>(tmodel);
        infoTable.setRowSorter(sort);
        infoTable.getSelectionModel().addListSelectionListener(infoTable);
        
        jButton2.setEnabled(true);
        processor.setEnabled(true);
        
        SpinnerNumberModel pmodel3 = (SpinnerNumberModel)processor.getModel();        
   
        pmodel3.setMaximum(p1);
        
        s.printStats();
        s.outWithIt();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        SpinnerNumberModel pmodel2 = (SpinnerNumberModel)processor.getModel();
        int p = pmodel2.getNumber().intValue();
        
        int anum = s.Processors.get(p-1).algo;
        
        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        
        model.setRowCount(0);
        model.setRowCount(300);
        
        switch(anum){
        
            case 0:
                if(p<=s.Gantt.size())
                {
                    LinkedList<Integer> ganttList = s.Gantt.get(p-1);

                    int start = 0, end = 0, pnum = 0, current=0, gnum=0;

                    for(int i=0; i<ganttList.size(); i++)
                    {
                        current = ganttList.get(i);

                        if(current==0)
                        {
                            if(pnum!=0){
                                end = i;
                                model.setValueAt(start, gnum, 0);
                                model.setValueAt(end, gnum, 1);
                                model.setValueAt(pnum, gnum, 2);
                                gnum++;
                            }
                        }else if(current!=pnum)
                        {
                            if(pnum==0)
                            {
                                start = i;

                            }else
                            {
                                end = i;
                                model.setValueAt(start, gnum, 0);
                                model.setValueAt(end, gnum, 1);
                                model.setValueAt(pnum, gnum, 2);
                                start = i;
                                gnum++;
                            }
                        }
                        pnum = current;
                        
                        if(i==ganttList.size()-1&&pnum!=0)
                        {
                            end = i;
                            model.setValueAt(start, gnum, 0);
                            model.setValueAt(end, gnum, 1);
                            model.setValueAt(pnum, gnum, 2);
                            gnum++;
                        }
                    }
                    model.setRowCount(gnum);
                }
                break;
              
            case 1:
                int q = s.Processors.get(p-1).quantum;
                
                if(p<=s.Gantt.size())
                {
                    LinkedList<Integer> ganttList = s.Gantt.get(p-1);

                    int start = 0, end = 0, pnum = 0, current=0, gnum=0;

                    for(int i=0; i<ganttList.size(); i++)
                    {
                        current = ganttList.get(i);

                        if(current==0)
                        {
                            if(pnum!=0){
                                end = i;
                                model.setValueAt(start, gnum, 0);
                                model.setValueAt(end, gnum, 1);
                                model.setValueAt(pnum, gnum, 2);
                                gnum++;
                            }
                        }else if(current!=pnum)
                        {
                            if(pnum==0)
                            {
                                start = i;

                            }else
                            {
                                end = i;
                                model.setValueAt(start, gnum, 0);
                                model.setValueAt(end, gnum, 1);
                                model.setValueAt(pnum, gnum, 2);
                                start = i;
                                gnum++;
                            }
                        }else if(i-start==q)
                        {
                            end = i;
                            model.setValueAt(start, gnum, 0);
                            model.setValueAt(end, gnum, 1);
                            model.setValueAt(pnum, gnum, 2);
                            start = i;
                            gnum++;
                        }
                       
                        pnum = current;
                        
                        if(i==ganttList.size()-1&&pnum!=0)
                        {
                            end = i;
                            model.setValueAt(start, gnum, 0);
                            model.setValueAt(end, gnum, 1);
                            model.setValueAt(pnum, gnum, 2);
                            gnum++;
                        }
                    }
                    model.setRowCount(gnum);
                }
                break;
            
            case 2:
                if(p<=s.Gantt.size())
                {
                    LinkedList<Integer> ganttList = s.Gantt.get(p-1);

                    int start = 0, end = 0, pnum = 0, current=0, gnum=0;

                    for(int i=0; i<ganttList.size(); i++)
                    {
                        current = ganttList.get(i);

                        if(current==0)
                        {
                            if(pnum!=0){
                                end = i;
                                model.setValueAt(start, gnum, 0);
                                model.setValueAt(end, gnum, 1);
                                model.setValueAt(pnum, gnum, 2);
                                gnum++;
                            }
                        }else if(current!=pnum)
                        {
                            if(pnum==0)
                            {
                                start = i;

                            }else
                            {
                                end = i;
                                model.setValueAt(start, gnum, 0);
                                model.setValueAt(end, gnum, 1);
                                model.setValueAt(pnum, gnum, 2);
                                start = i;
                                gnum++;
                            }
                        }
                        pnum = current;
                        
                        if(i==ganttList.size()-1&&pnum!=0)
                        {
                            end = i;
                            model.setValueAt(start, gnum, 0);
                            model.setValueAt(end, gnum, 1);
                            model.setValueAt(pnum, gnum, 2);
                            gnum++;
                        }
                    }
                    model.setRowCount(gnum);
                }
                break;
                
            default:
                break;
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void useFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useFileActionPerformed
        // TODO add your handling code here:
        filename.setEnabled((useFile.isSelected())?true:false);
        processes.setEnabled((useFile.isSelected())?false:true);
    }//GEN-LAST:event_useFileActionPerformed

    private void algoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algoActionPerformed
        // TODO add your handling code here:
        tquantum.setEnabled((algo.getSelectedIndex()==1)?true:false);
    }//GEN-LAST:event_algoActionPerformed

    private void useCommonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useCommonActionPerformed
        // TODO add your handling code here:
        useDifferent.setEnabled((useCommon.isSelected())?false:true);
        if(useCommon.isSelected())
            useDifferent.setSelected(false);
    }//GEN-LAST:event_useCommonActionPerformed

    private void algo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algo2ActionPerformed
        // TODO add your handling code here:
        SpinnerNumberModel model = (SpinnerNumberModel)processors2.getModel();    
        int p = model.getNumber().intValue();
        processorAlgorithms.set(p-1, algo2.getSelectedIndex());
        
        tquantum1.setEnabled((algo2.getSelectedIndex()==1)?true:false);
    }//GEN-LAST:event_algo2ActionPerformed

    private void useDifferentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useDifferentActionPerformed
        // TODO add your handling code here:
        processors2.setEnabled((useDifferent.isSelected())?true:false);
        algo2.setEnabled((useDifferent.isSelected())?true:false);
        
        SpinnerNumberModel pmodel = (SpinnerNumberModel)processors.getModel();        
   
        int p = pmodel.getNumber().intValue();
        for(int i=0; i<p; i++)
        {
            processorAlgorithms.add(i, 0);
            processorTimeQuantums.add(i,1);
        }
    }//GEN-LAST:event_useDifferentActionPerformed

    private void processorsStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_processorsStateChanged
        // TODO add your handling code here:
        SpinnerNumberModel pmodel = (SpinnerNumberModel)processors.getModel();        
   
        int p = pmodel.getNumber().intValue();
        
        SpinnerNumberModel model = (SpinnerNumberModel)processors2.getModel();        
   
        model.setMaximum(p);
        
        for(int i=0; i<p; i++)
        {
            processorAlgorithms.add(i, 0);
            processorTimeQuantums.add(i,1);
        }
    }//GEN-LAST:event_processorsStateChanged

    private void processors2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_processors2StateChanged
        // TODO add your handling code here:
        SpinnerNumberModel model = (SpinnerNumberModel)processors2.getModel();    
        int p = model.getNumber().intValue();
        
        SpinnerNumberModel pmodel = (SpinnerNumberModel)processors.getModel();        
   
        int p2 = pmodel.getNumber().intValue();
                
        if(p<=p2&&useDifferent.isSelected()){
            int a = processorAlgorithms.get(p-1);
            algo2.setSelectedIndex(processorAlgorithms.get(p-1));
            tquantum1.setValue(processorTimeQuantums.get(p-1));
            
            tquantum1.setEnabled((a==1)?true:false);
                
        }
        
    }//GEN-LAST:event_processors2StateChanged

    private void tquantum1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tquantum1StateChanged
        // TODO add your handling code here:
        SpinnerNumberModel model = (SpinnerNumberModel)processors2.getModel();    
        int p = model.getNumber().intValue();
        SpinnerNumberModel model2 = (SpinnerNumberModel)tquantum1.getModel();
        int q = model2.getNumber().intValue();
        processorTimeQuantums.set(p-1, q);
    }//GEN-LAST:event_tquantum1StateChanged

    private void pullActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pullActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pullActionPerformed

    private void pushActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pushActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pushActionPerformed

    private void pushFactorStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_pushFactorStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_pushFactorStateChanged

    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new UI().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox algo;
    private javax.swing.JComboBox algo2;
    private javax.swing.JTextField avgTT;
    private javax.swing.JTextField avgWT;
    private javax.swing.JTextField filename;
    private javax.swing.JTable infoTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JSpinner processes;
    private javax.swing.JSpinner processor;
    private javax.swing.JSpinner processors;
    private javax.swing.JSpinner processors2;
    private javax.swing.JCheckBox pull;
    private javax.swing.JCheckBox push;
    private javax.swing.JSpinner pushFactor;
    private javax.swing.JSpinner tquantum;
    private javax.swing.JSpinner tquantum1;
    private javax.swing.JCheckBox useCommon;
    private javax.swing.JCheckBox useDifferent;
    private javax.swing.JCheckBox useFile;
    // End of variables declaration//GEN-END:variables


}

